<?php

class Nld_System
{
	static function config($index = null)
	{
		$config = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOptions();
		return ($index == null)?$config:@$config[$index];
	}
	static function Authorized($object, $acl)
	{
		return Nld_Acl::cached()->isAllowed($object, $acl);
	}
	static function UserLogin($username, $password)
	{
		return Nld_Auth_Users::getInstance()->authenticate(
			new Nld_Auth_Users_Db($username, $password));
	}
	static function UserDoLogout()
	{
		Nld_Auth_Users::getInstance()->clearIdentity();
	}
	static function UserCurrent()
	{
		return Nld_Auth_Users::getInstance()->getIdentity();
	}
	static function UserIsLogin()
	{
		return Nld_Auth_Users::getInstance()->hasIdentity();
	}
	static function UserDoAuthorized($acl)
	{
		if(!self::Authorized('user:'.@self::UserCurrent()->username, $acl))
		{
			throw new Exception($acl, 403);
		}
	}
	static function UserHasAuthorized($acl)
	{
		return self::Authorized('user:'.self::UserCurrent()->username, $acl);
	}
}